package com.sa.web.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.sa.web.bean.QaBean;
import com.sa.web.bean.UserBean;
import com.sa.web.dao.service.QaDao;
import com.sa.web.dao.service.UserDao;

/**
 * 用户DAO
 */

public class QaDaoImpl implements QaDao {

	// 获取连接池
	private SqlMapClientTemplate sqlMapClientTemplate;

	/**
	 * 获得用户信息列表（后台）
	 */
	@Override
	public List<QaBean> getQaInfo(int pageNumber,int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("pageNumber", pageNumber);
		map.put("pageSize", pageSize);
		return (List<QaBean>)sqlMapClientTemplate.queryForList("getQaInfo",map);
	}
	
	/**
	 * 获得用户信息列表（后台）
	 */
	@Override
	public Integer getQaCount() {
		return (Integer) sqlMapClientTemplate.queryForObject("getQaCount");
	}
	
	/**
	 * 删除留学问答(后台)
	 */
	public boolean deleteQaInfo(String qaId){
		return sqlMapClientTemplate.delete("deleteQaInfo",qaId)>0;
	}

	@Override
	public boolean addQaInfo(QaBean qaBean) {
		return (Integer)sqlMapClientTemplate.insert("addQaInfo", qaBean)>0;
	}
	
	@Override
	public Integer queryQaCount() {
		return (Integer) sqlMapClientTemplate.queryForObject("queryQaCount");
	}
	
	@Override
	public List<QaBean> queryQaInfo(int currentPage, int pageCount) {		
		return sqlMapClientTemplate.queryForList("getQaInfoList", (currentPage-1)*pageCount, currentPage*pageCount);
	}
	
	public SqlMapClientTemplate getSqlMapClientTemplate() {
		return sqlMapClientTemplate;
	}

	public void setSqlMapClientTemplate(
			SqlMapClientTemplate sqlMapClientTemplate) {
		this.sqlMapClientTemplate = sqlMapClientTemplate;
	}

}
